package service

import (
	"database/sql"
	"fmt"
)

type SystemSonfig struct {
	Id      int    `db:"Id"`
	SysType string `db:"sys_type"`
	SysVal  string `db:"sys_val"`
}

func QueryData() []SystemSonfig {
	database, err := sql.Open("mysql", "root:root@tcp(127.0.0.1:3306)/testconfig")
	if err != nil {
		fmt.Println("open mysql failed,error:", err)
		return []SystemSonfig{}
	}
	var systemSonfigs []SystemSonfig
	rows, _ := database.Query("select * from system_config")
	for rows.Next() {
		var config SystemSonfig
		err := rows.Scan(&config.Id, &config.SysType, &config.SysVal)
		if err != nil {
			fmt.Println("rows fail")
		}
		systemSonfigs = append(systemSonfigs, config)
	}
	fmt.Println(systemSonfigs)
	return systemSonfigs
}
